function getUserInfo() {
  $.ajax({
    url: '/my/userinfo',
    success(res) {
      if (res.status !== 0) {
        return;
      }
      let data = res.data;
      let name = data.nickname || data.username;
      $('.username').html('欢迎&nbsp;&nbsp;' + name);
      if (!data.user_pic) {
        let str = data.username.slice(0, 1).toUpperCase();
        $('.avatar').text(str);
      } else if (data.user_pic) {
        $('.avatarImg').attr('src', data.user_pic);
        $('.avatarImg').show().siblings('.avatar').hide();
      }
      localStorage.setItem('id', data.id);
    },
  });
}
$(() => {
  getUserInfo();
  $('.exit').click(function () {
    layer.confirm(
      '您确定要退出登录吗?',
      { icon: 3, title: '提示' },
      function (i) {
        //do something
        location.href = '/bigevent/home/login.html';
        localStorage.removeItem('token');
        layer.close(i);
      }
    );
  });
});
